/**
* 版权声明：厦门睿商网络科技有限公司 版权所有 违者必究
* 日    期：2020-07-22
*/
package com.rzico.basics.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.rzico.annotation.Log;
import com.rzico.base.BaseController;
import com.rzico.base.CommResult;
import com.rzico.basics.entity.Bom;
import com.rzico.basics.entity.Enterprise;
import com.rzico.basics.entity.Product;
import com.rzico.basics.service.BomItemService;
import com.rzico.basics.service.BomService;
import com.rzico.basics.service.EnterpriseService;
import com.rzico.basics.service.ProductService;
import com.rzico.entity.PageResult;
import com.rzico.entity.Pageable;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 商品清单控制层
 *
 * @author Rzico Boot
 * @version 1.0
 * @date 2020-07-22
 */
@Api(description = "商品清单接口")
@RestController
@RequestMapping("/bom")
public class BomController extends BaseController {

    @Autowired
    private BomService bomService;

    @Autowired
    private BomItemService bomItemService;

    @Autowired
    private EnterpriseService enterpriseService;

    @Autowired
    private ProductService productService;

    /**
     * 通过水票获取对应桶装水
     *
     * @return
    */
    @ApiOperation("通过水票获取对应桶装水")
    @GetMapping("/findByWater")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "productId", value = "所属商品", dataType = "Long", paramType = "query")
    })public CommResult<Bom> findByWater(Long productId) {

        Map<String,Object> params = new HashMap<>();
        params.put("type",2);
        params.put("productId",productId);

        List<Bom> bomList = bomService.selectList(params);
        if (bomList.size()==0) {
            return CommResult.error("没有维护水票信息");
        }
        Bom result = bomList.get(0);
        result.setItemList(bomItemService.getItemList(result.getId()));
        if (result.getItemList().size()==0) {
            return CommResult.error("没有维护水票信息");
        }

        return CommResult.success(result.getItemList().get(0));

    }


}
